<?php
class Default_Model_DbTable_Video extends Zend_Db_Table_Abstract {
	protected $_name = 'video';
	// Add video
	public function AddVideo($VName, $Video, $Stt, $VLibID, $img) {
		$VideoData = array (
				"VIDEO_NAME" => $VName,
				"VIDEO" => $Video,
				"STATUS" => $Stt,
				"VIDEO_LIB_ID" => $VLibID,
				"IMG" => $img 
		);
		$this->insert ( $VideoData );
	}
	// update video
	public function UpdateVideo($Id, $VName, $Video, $Stt, $VLibID, $img) {
		$VideoData = array (
				"VIDEO_NAME" => $VName,
				"VIDEO" => $Video,
				"STATUS" => $Stt,
				"VIDEO_LIB_ID" => $VLibID,
				"IMG" => $img 
		);
		$this->update ( $VideoData, "ID = $Id" );
	}
	// remove video
	public function RemoveVideo($Id) {
		return $this->delete ( "ID = $Id" );
	}
	// update status
	public function UpStt($Id, $Stt) {
		$VideoData = array (
				"STATUS" => $Stt 
		);
		$this->update ( $VideoData, "ID = $Id" );
	}
	// get all video
	public function GetAll() {
		$select = $this->select ( Zend_Db_Table::SELECT_WITH_FROM_PART )->setIntegrityCheck ( false );
		$select->from ( "video as v" )->joinLeft ( "lib_video as lv", "lv.ID = v.VIDEO_LIB_ID", array (
				"lv.LIB_NAME" 
		) )->group ( "v.ID" );
		return $video = $this->fetchAll ( $select );
	}
	
	// show video index
	public function ShowVideo() {
		$select = $this->select ()->from ( $this->_name, array (
				"VIDEO",
				"VIDEO_NAME",
				"IMG" 
		) )->where ( "STATUS = 1" )->group ( "ID" );
		return $this->fetchAll ( $select );
	}
	// get video by id
	public function GetByID($Id) {
		return $video = $this->fetchRow ( "ID = $Id" );
	}
	// get video by VIDEO_LIB_ID
	public function GetByVideoLibID($VidLibID) {
		return $video = $this->fetchAll ( "VIDEO_LIB_ID = $VidLibID" )->toArray ();
	}
	// change status
	public function Active($id) {
		$video = $this->GetByID ( $id );
		if ($video->STATUS == 1) {
			$this->update ( array (
					"STATUS" => "0" 
			), "ID = $id" );
		} else {
			$this->update ( array (
					"STATUS" => "1" 
			), "ID = $id" );
		}
	}
}

